package com.mind.ridge.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mind.ridge.dto.front.OrderDto;
import com.mind.ridge.pojo.front.OrderDetail;
import com.mind.ridge.pojo.front.Orders;
import com.mind.ridge.pojo.front.ShoppingCart;
import com.mind.ridge.service.front.OrderDetailService;
import com.mind.ridge.service.front.OrdersService;
import com.mind.ridge.utils.OrderException;
import com.mind.ridge.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * @author Mind
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Resource
    private OrdersService ordersService;

    @PostMapping("/submit")
    public R<String> submit(HttpSession session, @RequestBody Orders order) throws OrderException {
        log.info(order.toString());
        return ordersService.submit(session, order);
    }

    @GetMapping("/userPage")
    public R<IPage<Orders>> userPage(int page, int pageSize, HttpSession session) {
        return ordersService.userPage(page, pageSize, session);
    }

    @GetMapping("/page")
    public R<IPage<OrderDto>> page(int page, int pageSize, HttpSession session) {
        return ordersService.orderPage(page, pageSize);
    }

    @PutMapping()
    public R<String> update(@RequestBody Orders order) {
        return ordersService.changeOrderStatus(order);
    }

    @PostMapping("/again")
    public R<String> again(@RequestBody Orders order, HttpSession session) {
        return ordersService.again(order, session);
    }
}
